<?php

class Default_Form_Login extends Zend_Form {

    public function init() {
        $this->setAction('')->setMethod('post');

        $userName = $this->createElement('text', 'txtUserId', array('label' => 'Tài khoản: '));
        $password = $this->createElement('password', 'prdPassword', array('label' => 'Mật khẩu: '));

        $sctChat = $this->createElement('select', 'sctChat', array('label' => 'Chat với: '));

        $tb_Users = new Default_Model_Users();
        $users = $tb_Users->fetchAll("IsOnline = 1")->toArray();

        if ($users != NULL) {
            foreach ($users as $key => $value) {
                $x = '^_^ ' . $value['UserId'];
                $arr[$value['UserId']] = $x;
            }
        }
        $users = $tb_Users->fetchAll("IsOnline = 0")->toArray();
        if ($users != NULL) {
            foreach ($users as $value) {
                $x = '$_$ ' . $value['UserId'];
                $arr[$value['UserId']] = $x;
            }
        }
        $sctChat->addMultiOptions($arr);

        $this->addElement($userName)
                ->addElement($password)
                ->addElement($sctChat)
                ->addElement('submit', 'frmLogin', array('label' => 'Đăng nhập'));
    }

    // Cach tao form, tao them 1 so validator
    public function bakInit() {
        $this->setAction('')->setMethod('post');
        $username = $this->createElement('text', 'txtUserId', array('label' => 'Tài khoản: '));
        $username->addValidator('alnum')
                ->addValidator('regex', false, array('/^[a-z]+/'))
                ->addValidator('stringLength', false, array(6, 20))
                ->setRequired(true)
                ->addFilter('StringToLower');

        $password = $this->createElement('password', 'prdPassword', array('label' => 'Mật khẩu: '));
        $password->addValidator('StringLength', false, array(6))
                ->setRequired(true);

        $this->addElement($username)
                ->addElement($password)
                ->addElement('submit', 'frmLogin', array('label' => 'Đăng nhập'));
    }

}